package com.example.lenovo.recyclerviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Fruit> fruitList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFruits();
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        FruitAdapter adapter = new FruitAdapter(fruitList);
        recyclerView.setAdapter(adapter);
    }

    private void initFruits() {
        for (int i = 0; i < 4; i++) {
            Fruit apple = new Fruit("雄鹿", R.drawable.xionglu);
            fruitList.add(apple);
            Fruit apple1 = new Fruit("猛龙", R.drawable.menglong);
            fruitList.add(apple1);
            Fruit apple2 = new Fruit("76人", R.drawable.feicheng);
            fruitList.add(apple2);
            Fruit apple3 = new Fruit("活塞", R.drawable.huosai);
            fruitList.add(apple3);
            Fruit apple4 = new Fruit("勇士", R.drawable.yongshi);
            fruitList.add(apple4);
            Fruit apple5 = new Fruit("掘金", R.drawable.juejing);
            fruitList.add(apple5);
            Fruit apple6 = new Fruit("开拓者", R.drawable.kaituozhe);
            fruitList.add(apple6);
            Fruit apple7 = new Fruit("火箭", R.drawable.huojian);
            fruitList.add(apple7);
        }
    }
}
